#include <stdio.h>
#include <Ecore_X.h>
#include <X11/Xlib.h>
#include <X11/extensions/shape.h>

/**
 * @brief Overrides ecore_x_window_hide(). This is used to prevent e17 from unmapping windows when they
 * are iconified, hidden or when virtual desktops is changed. This way, the glx pixmap is not destroyed each time
 * one of these events happens, which makes Egloo run faster. It also allows to have live thumbs of minimized windows
 * or to display windows that are not on the current virtual desktop for example.
 * @param win the window that should have been hidden
 */
void ecore_x_window_hide(Ecore_X_Window win)
{
   Ecore_X_Display *dpy = ecore_x_display_get();
   
   XRectangle rect = { .x = 0, .y = 0, .width = 0, .height = 0 };
   
   /* Make the window transparent to mouse events */
   XShapeCombineRectangles(dpy, win, ShapeInput, 0, 0, &rect, 1, ShapeSet, Unsorted);
   /* TODO/Fixme: we can still drop (dnd) something in a window that has been hidden (Gtk)...
    * with XSelectInput() maybe?? */
}
 
/**
 * @brief Overrides ecore_x_window_show()
 * @param win the window that should be shown
 */
void ecore_x_window_show(Ecore_X_Window win)
{
   Ecore_X_Display *dpy = ecore_x_display_get();
   
   /* Makes the window sensitive to mouse events again and then maps the window */
   XShapeCombineMask(dpy, win, ShapeInput, 0, 0, 0, ShapeSet);
   XMapWindow(dpy, win);
}
